package DesignPatterns.FactoryMode.order;

import DesignPatterns.FactoryMode.coffee.Coffee;

import java.util.Scanner;

public class OrderCoffee {
    SimpleFactory simpleFactory;
    static Coffee coffee=null;
    MethodFactory methodFactory;

    public OrderCoffee(SimpleFactory simpleFactory, MethodFactory methodFactory) {
        this.simpleFactory = simpleFactory;
        this.methodFactory = methodFactory;
    }

    //简单工厂
    public static void setCoffee(SimpleFactory simpleFactory, String type){
        coffee = simpleFactory.CreatCoffee(type);
        if(coffee!=null){
            coffee.ok();
        } else {
            System.out.println("无此咖啡");
        }
    }
    public static void setCoffee(MethodFactory methodFactory,String type){
        coffee=methodFactory.createCoffee(type);
        if(coffee!=null){
            coffee.ok();
        } else {
            System.out.println("无此咖啡");
        }
    }
    public OrderCoffee(SimpleFactory simpleFactory) {
        this.simpleFactory = simpleFactory;
    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        SimpleFactory simpleFactory=new SimpleFactory();
        while (true){
            String CoffeeType=sc.next();
            setCoffee(simpleFactory,CoffeeType);//简单工厂模式
            setCoffee(new createAmericanCoffee(),CoffeeType);//方法工厂
            setCoffee(new createLatteCoffee(),CoffeeType);

        }
    }
}
